// pages/user/evaluate/evaluate.js
var api = require("../../../api.js"),
    app = getApp();
const handler=require("../../../utils/function.js")
Page({
    /**
     * 页面的初始数据
     */
    data: {
        img: handler.userImg,
        driver: [],
        order: wx.getStorageSync("orderDetail"),
        satisfaction: ["满意", "一般", "不满意"],
        checkSatisfaction: -1,
        question: [],
        checkQuestion: -1,
        idea: -1,
        order_no: '',
        graded: '',
        spendTime: 0, //服务时长
        distance: 0, //里程
        cid: 0, //里程
        display: "none",
        display_1: "none",
        display_2: "none",
        display_3: "none",
        display_4: "none",
        display_5: "none",
        xing: 0
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.setData({
            order_no: options.order_no
        })
    },
    // satisfactionHandler 满意度选择
    satisfactionHandler: function(e) {
        this.setData({
            checkSatisfaction: e.currentTarget.dataset.id
        });
    },
    // questionHandler 存在问题选择
    questionHandler: function(e) {
        console.log('获取订单号', e)
        this.setData({
            checkQuestion: e.currentTarget.dataset.id,
            cid: e.currentTarget.dataset.cid
        });
    },
    // ideaHandler 意见事件
    ideaHandler: function(e) {
        console.log('一键', e)
        this.setData({
            idea: e.detail.value
        });
    },
    // evaluateSubmitHandler 匿名提交事件
    evaluateSubmitHandler: function() {
        var that = this;
      // satisfaction: that.data.satisfaction[that.data.checkSatisfaction],
        app.request({
            url: api.order_comment.order_comment,
            method: 'post',
            data: {
                satisfaction: that.data.xing,
                cid: that.data.cid,
                idea: that.data.idea,
                driverid: that.data.driver.id,
                order_no: that.data.order_no,
            },
            success: function(rs) {
                console.log('意见提交', rs.data)
                wx.showToast({
                    title: rs.msg,
                    icon: 'none',
                    duration: 2000
                })
            }
        })
    },
  //显示选中星星
  show_this: function (e) {
    var that = this;
    if (e.target.dataset.num == 1) {
      this.setData({
        display_1: "block"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 2) {
      this.setData({
        display_1: "block",
        display_2: "block"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 3) {
      this.setData({
        display_1: "block",
        display_2: "block",
        display_3: "block"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 4) {
      this.setData({
        display_1: "block",
        display_2: "block",
        display_3: "block",
        display_4: "block"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 5) {
      this.setData({
        display_1: "block",
        display_2: "block",
        display_3: "block",
        display_4: "block",
        display_5: "block"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    console.log(e.target.dataset.num)
  },
  //取消选中星星
  hide_this: function (e) {
    var that = this;
    if (e.target.dataset.num == 5) {
      this.setData({
        display_1: "block",
        display_2: "block",
        display_3: "block",
        display_4: "block",
        display_5: "block"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 4) {
      this.setData({
        display_5: "none"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 3) {
      this.setData({
        display_4: "none",
        display_5: "none"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 2) {
      this.setData({
        display_3: "none",
        display_4: "none",
        display_5: "none"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 1) {
      this.setData({
        display_2: "none",
        display_3: "none",
        display_4: "none",
        display_5: "none"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
  },

    // 验证提交信息
    testHandler: function(params, message) {
        if (params !== -1) {
            return true;
        } else {
            wx.showToast({
                title: message,
                icon: 'none',
                duration: 2000
            })
        }
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        var that = this;
        app.request({
            url: api.order_comment.getinfo,
            method: 'post',
            data: {
                order_no: that.data.order_no,
            },
            success: function(rs) {
                console.log('sdsadsa', rs)
                if (rs.code == 1) {
                    that.setData({
                        question: rs.data.problem,
                        driver: rs.data.driver,
                        graded: rs.data.graded,
                        spendTime: rs.data.spendTime,
                        distance: rs.data.distance,
                    })
                  wx.navigateBack({
                    delta: 1
                  })
                } else {
                  wx.showToast({
                      title: rs.msg,
                  })
                  wx.navigateBack({
                    delta: 1
                  })
                }
            }
        })
        this.setData({
            driver: wx.getStorageSync("driverDetail"),
            order: wx.getStorageSync("orderDetail")
        });
    },
    
})